"""author: wenyao
   data: 2021/5/18
   project: devopscmdb
"""

import time
#
# def func1():
#     time.sleep(2)
#     print(f"func1....")
#
# def func2():
#     time.sleep(3)
#
# start = time.time()
# func1()
# end = time.time()
# print(end - start)
#
# start = time.time()
# func2()
# end = time.time()
# print(end - start)


#装饰器
#  不改变函数或类的源代码的基础上，添加额外功能
#  装饰器的本质就是闭包函数， 它需要把函数作为参数传递进来

#统计运行时间的装饰器
# def runtime(func):
#     def inner():
#         start = time.time()
#         func()
#         print(id(func))
#         end = time.time()
#         rt = end - start
#         print(rt)
#     return inner

# @runtime      #-->func1 = runtime(func1)
# def func1():
#     time.sleep(2)
#     print(f"func1....")

# @runtime
# def func2():
#     time.sleep(3)
#
# func1()
# print(id(func1))
# func2()
# inner = runtime(func1)
# inner()
# inner2 = runtime(func2)
# inner2()



username = input("请输入用户名:")

def login_required(func):
    print("i am login required....")
    def inner(a, b):
        if username == "root":
            result = func(a, b)
            #print(func.__name__)
            return result
        else:
            print("没有权限")
            return None
    return inner

@login_required  #add = login_required(add)
def add(a,b):
    return a+b

@login_required
def add2(a, b):
    return a+b

print(add(3,4))